package org.deng.vertx.springboot.web.controller;

import io.vertx.core.http.HttpMethod;
import io.vertx.core.json.JsonObject;
import io.vertx.ext.auth.User;
import io.vertx.ext.web.Router;
import io.vertx.ext.web.RoutingContext;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Component;

/**
 * @author 邓力宾
 * @date 2022/12/29 10:42
 * @desc
 */
@Slf4j
@Component
public class ProtectedController extends BaseController {
    @Override
    public void configRouter(Router router) {
        //登录认证
        router.route("/protected/*").handler(jwtAuthHandler);

        router.route("/protected/list").method(HttpMethod.GET).blockingHandler(this::list);
    }

    private void list(RoutingContext ctx) {
        User user = ctx.user();
        JsonObject principal = user.principal();
        writeJSON(ctx, principal);
    }
}
